package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.squareup.picasso.Picasso;

import liumengbaio.lolzhangyoubao.Activity.InFo.AdPic;
import liumengbaio.lolzhangyoubao.Activity.Activity.RollPagerDetals;

/**
 * Created by lanouhn on 16/8/24.
 */
public class RollPagerAdapter extends StaticPagerAdapter {
    private AdPic adPic;
    private Context mContext;
    private RollPagerView rollPagerView;

    public RollPagerAdapter(AdPic adPic, Context context, RollPagerView rollPagerView) {
        this.adPic = adPic;
        this.mContext = context;
        this.rollPagerView = rollPagerView;
    }

    @Override
    public View getView(ViewGroup container, int position) {
        ImageView view = new ImageView((container.getContext()));
        Picasso.with(mContext).load(adPic.getData().get(position).getPic_ad_url()).into(view);
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        final AdPic.DataBean.GotoParamBean bean=adPic.getData().get(position).getGoto_param();
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, RollPagerDetals.class);
                Bundle bundle=new Bundle();
                String path_next="http://lol.zhangyoubao.com/mobiles/item/" +
                        bean.getItemid() +
                        "?user_id=&token=&i_=EAC1B788-00BC-454A-A9B" +
                        "9-460852CFC011&t_=1438745027&p_=17426&v_=400503" +
                        "03&d_=ios&osv_=8.3&version=0&a_=lol&size=middle";
                bundle.putString("url",path_next);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });


        return view;
    }

    @Override
    public int getCount() {
        return adPic.getData().size();
    }
}
